package trash.Tmp;


public class StringTest
{
    public static void main(String[] args)
    {
        // Create new object in pool
        String s1 = "It is new String in String Pool";

        // Create string from char array
        char[] strArray = {'I', 't', ' ', 'i', 's', ' ', 'a', 'r', 'r', 'a', 'y'};
        String s2 = new String(strArray);

        //Concat and String-specific "operator+"
        String cs1 = "ABC";
        String cs2 = "123";
        String csout = cs1.concat(cs2) + s1 + 5 + s2 + 9000;
        csout = cs1;

        //System.out.printf and String.format
        System.out.printf("float : %f, int : %d, String : %s, char : %c\n", 123.456789f, 1123456789, "Text lala", '$');
        String sf = String.format("%s%c%f", "PI", '=', 3.14159265f);
        System.out.println(sf);

        // The Class String is immutable. You must use StringBuffer and StringBuilder for modifications
        //StringBuffer - Mutable String, synchronized
        //StringBuilder - Mutable String NOT synchronized

        StringBuffer stringBuffer = new StringBuffer(10);
        System.out.println("capacity = " + stringBuffer.capacity());
        System.out.println("length = " + stringBuffer.length());
        System.out.println("[" + stringBuffer.toString() + "]");
        stringBuffer.append("123456789012345");
        stringBuffer.replace(2, 3, "T");
        stringBuffer.setCharAt(0, 'X');
        System.out.println("capacity = " + stringBuffer.capacity());
        System.out.println("length = " + stringBuffer.length());
        System.out.println("[" + stringBuffer.toString() + "]");

        //AutoBoxing/Unboxing
        Object obj = 5;
        System.out.println(obj.getClass().toString() + " " + (Integer)obj);
        int x = (Integer)obj;
        System.out.println(x);
    }
}
